#!/bin/bash -e

PROJECT_ROOT=$(readlink -f $(dirname $0)/..)
BUILD_DIR=${PROJECT_ROOT}/build-ci
echo "${DISTRO} ${PROJECT_ROOT}"
c++ --version

if [[ -e ${BUILD_DIR} ]]; then
    echo "Build directory (${BUILD_DIR}) unclean -- deleting it"
    rm -rf ${BUILD_DIR}
fi
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}

if $(hash lcov 2>/dev/null); then
  # TODO(https://github.com/tgockel/zookeeper-cpp/issues/42): Disabling Coveralls coverage for now.
  COVERAGE=0
else
  COVERAGE=0
fi

cmake .. -DZKPP_BUILD_OPTION_CODE_COVERAGE=${COVERAGE}
make VERBOSE=1
make test

if [[ ${COVERAGE} -eq 1 ]]; then
  ${PROJECT_ROOT}/config/upload-coverage ${BUILD_DIR}
fi
